<?php

define("COUNTER_COOKIE_NAME","Swing_Counter"); //definicia nazvu cookie



//-------------------------------------------------------------------
//Nazov:		Counter_Get_Value
//Popis:		Otvorenie databazy a zistenie udaju stavu pocitadla
//Navrat.hodn:	Typ INT - hodnota pocitadla
//-------------------------------------------------------------------
function Counter_Get_Value(){
	$sql= "SELECT Counter_Value FROM counter";	
	$sql_array = mysql_fetch_object(mysql_query($sql));
	$Counter_Value = $sql_array->Counter_Value;
	return $Counter_Value;
}


//-------------------------------------------------------------------
//Nazov:		Counter_Increment
//Popis:		Zmena hodnoty pocitadla v DB
//-------------------------------------------------------------------
function Counter_Increment(){
    $sql="UPDATE counter SET Counter_Value=".(Counter_Get_Value()+1);
    mysql_query($sql);
}


//-------------------------------------------------------------------
//Nazov:		Counter_Print
//Popis:		V�pis hodnoty pocitadla
//-------------------------------------------------------------------
function Counter_Print(){
	print Counter_Get_Value();
}


//-------------------------------------------------------------------
//Nazov:		Counter_Start
//Popis:		Ak je stranka otvorena poprvykrat od zapnutia 
//				prehliadaca, (cookie neexistuje)tak bude hodnota 
//				pocitadla inkrementovana
//-------------------------------------------------------------------
function Counter_Start(){
    if (!isset($_COOKIE[COUNTER_COOKIE_NAME])){
    	Counter_Increment();
    	setcookie(COUNTER_COOKIE_NAME);
    }  
}

?>